<?php
/**
 * Created by PhpStorm.
 * User: ly
 * Date: 2018\1\13 0013
 * Time: 11:47
 */
use yii\widgets\LinkPager;
use common\models\UserModel;
?>

<style type="text/css">
    .project {
        background: #deeffd;
        color: #2194f1!important;
        text-align: center;
        line-height: 20px;
        font-size: 12px;
        border-radius: 2px;
    }
</style>
<!--资产包详情列表结开始-->
<div class="myProject">
    <div class="container">
        <div class="row ">

            <?PHP if(count($data)>0){?>
                <div class="details-btns clearfix">
                    <button type="button" id="setTeam" data-toggle="modal" data-target="#myModal2"  class="btn btn-default details-btn pull-right">
                        <img src="/image/assetPackage/td.png" class="pull-left ">
                        <span class="pull-left">配置团队</span>
                    </button>
                    <button type="button" id="setPermission" data-toggle="modal" data-target="#myModal" class="btn btn-default details-btn pull-right">
                        <img src="/image/assetPackage/xgfwqx.png" class="pull-left ">
                        <span class="pull-left  ">修改访问权限</span>
                    </button>
                </div>
                <!-- biaoge -->
                <div class="clearfix myProject-table-wrap" style=" border: 1px solid #eeeeee; overflow: hidden;">
                    <table class="myProject-table">
                        <thead style="" class="thead-normal">
                        <tr>
                            <th class="text-center">序号</th>
<!--                            <th class="text-center">项目编号</th>-->
                            <th class="text-center" sort="borrower">借款人名称</th>
                            <th class="text-center" sort="city">省份地区</th>
                            <th class="text-center"  width="40" sort="principal">本金</th>
                            <th class="text-center"  width="60" sort="type2">项目类型</th>
                            <th class="text-center"  width="100" sort="title">隶属资产包</th>
                            <th class="text-center" sort="realname">项目经理</th>
                            <th class="text-center" width="120">团队成员</th>
                            <th class="text-center" width="120" sort="guarantor">保证人/抵押人</th>
                            <th class="text-center" sort="status">当前状态</th>
                            <th class="text-center " sort="highlights">亮点明细</th>
                            <th class="text-center ">详情</th>
                        </tr>
                        </thead>
                        <thead style="" class="thead-fixed">
                        <tr>
                            <th class="text-center">序号</th>
<!--                            <th class="text-center">项目编号</th>-->
                            <th class="text-center" sort="borrower">借款人名称</th>
                            <th class="text-center" sort="city">省份地区</th>
                            <th class="text-center" width="40" sort="principal">本金</th>
                            <th class="text-center" width="60" sort="type2">项目类型</th>
                            <th class="text-center"  width="100" sort="title">隶属资产包</th>
                            <th class="text-center" sort="realname">项目经理</th>
                            <th class="text-center"  width="120">团队成员</th>
                            <th class="text-center" width="120" sort="guarantor">保证人/抵押人</th>
                            <th class="text-center" sort="status">当前状态</th>
                            <th class="text-center " sort="highlights">亮点明细</th>
                            <th class="text-center ">详情</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?PHP
                        $i = (Yii::$app->request->get('page',1)-1)*10;
                        $project_state=Yii::$app->params['project_state'];
                        $package_type=Yii::$app->params['package_type'];
                        $usermodel=new UserModel();
                        foreach ($data as $value) {
                            $i++;
                            $partner=$usermodel->getUserStrNdepartment($value['partner']);
                            $star='';
                            if($value['is_highlights']==1){
                                $star='<img src="/image/assetPackage/star.png" class="pull-left">';
                            }
                            //  <td title="' . $value['code'] . '"><span class="txt-cut">' . $value['code'] . '</span></td>
                            echo ' <tr class="text-left">
                                    <td class="clearfix">
                                        <div class="clearfix">
                                            <input type="checkbox" name="checkboxID" value="' . $value['id'] . '" class="pull-left list-input selinput">
                                            <span class="pull-left">' . $i . '</span>'.$star.'
                                        </div>
                                    </td>
                                    <td title="'.$value['borrower'].'"><span class="txt-cut">'.$value['borrower'].'</span></td>
                                    <td title="'.$value['provinceName'].$value['cityName'].'"><span class="txt-cut">'.$value['provinceName'].$value['cityName'].'</span></td>
                                    <td title="'.$value['principal'].'"><span class="txt-cut">'.Yii::$app->formatter->asDecimal($value['principal']).'</span></td>
                                    <td title=""><span class="txt-cut">'.$package_type[$value['type2']].'</span></td>
                                    <td title="'.$value['title'].'"><a target="_blank" href="/package/detail-info?packageid='.$value['package_id'].'"><span class="txt-cut">'.$value['title'].'</span></a></td>
                                    <td title="'.$value['realname'].'"><span class="txt-cut">'.$value['realname'].'</span></td>
                                    <td title="'.$partner.'"><span class="txt-cut">'.$partner.'</span></td>
                                    <td title="'.$value['guarantor'].'"><span class="txt-cut">'.$value['guarantor'].'</span></td>
                                    <td title=""><span class="txt-cut project">'.$project_state[$value['status']].'</span></td>
                                    <td title="'.$value['highlights'].'"><span class="txt-cut">'.$value['highlights'].'</span></td>
                                    <td title="查看"><a href="/project/getinfodata?package_id='.$value['package_id'].'&project_id='.$value['id'].'" ><span class="txt-cut">查看</span></a></td>
                                </tr>';
//                        $project = $value['project'];
//                        $package = $project['package'];
//                        echo ' <tr class="text-left">
//                                    <td class="clearfix">
//                                        <div class="clearfix">
//                                            <input type="checkbox" name="checkboxID" value="' . $project['id'] . '" class="pull-left list-input">
//                                            <img src="/image/assetPackage/star.png" class="pull-left">
//                                            <span class="pull-left">' . $i . '</span>
//                                        </div>
//                                    </td>
//                                    <td title="' . $project['code'] . '"><span class="txt-cut">' . $project['code'] . '</span></td>
//                                    <td title="'.$project['title'].'"><span class="txt-cut">'.$project['title'].'</span></td>
//                                    <td title="江苏省盐城市"><span class="txt-cut">'.$project['provinceName']['title'].$project['cityName']['title'].'</span></td>
//                                    <td title=" 6,210,000.00"><span class="txt-cut">'.$project['principal'].'</span></td>
//                                    <td title=""><span class="txt-cut">'.$project['type2'].'</span></td>
//                                    <td title="'.$package['title'].'"><span class="txt-cut">'.$package['title'].'</span></td>
//                                    <td title=""><span class="txt-cut">'.$value['manager'].'</span></td>
//                                    <td title="田壮，丁峰， 王玲，李帅 睿以"><span class="txt-cut">'.$value['partner'].'</span></td>
//                                    <td title="江苏盐城产业投资有限公司"><span class="txt-cut">'.$project['guarantor'].'</span></td>
//                                    <td title=""><span class="txt-cut">'.$project['status'].'</span></td>
//                                    <td title="房屋项下土地也登记在由由（集团）有限公司"><span class="txt-cut">'.$project['highlights'].'</span></td>
//                                    <td title="查看"><a href="/project/getinfodata?package_id='.$project['package_id'].'&project_id='.$project['id'].'" ><span class="txt-cut">查看</span></a></td>
//                                </tr>';
                        }
                        ?>
                        </tbody>
                    </table>
                </div>
                <div class="pagingBox">
                    <?PHP
                    echo LinkPager::widget([
                        'pagination' => $pages,
                        'firstPageLabel' => '首页',
                        'lastPageLabel' => '尾页',
                        'nextPageLabel' => '下一页',
                        'prevPageLabel' => '上一页'
                    ]);
                    ?>
                    <div style="float: right;margin: 25px 0;"><span  class="totalSize">共<?php echo $pages->totalCount;?></span>条记录</div>
                </div>
            <?PHP
            }else{
                echo '<div class="defaultPage">
                    <div class="defaultPage-nothing">
                        <img src="/image/defaultPage/nothing.png" style="width: 100%;">
                    </div>
                </div>';
            }?>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal">
</div>

<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModal2">
</div>
<script>
    //<span class="glyphicon glyphicon-triangle-bottom"></span>是否存在排序并调整排序后的显示
    var sortStr='<?php echo Yii::$app->request->get('sort','');?>';
    //表头排序可排序的用手指
    $('.myProject-table thead tr th ').each(function () {
        if($(this).attr('sort')!=undefined){
            $(this).css({'cursor':'pointer'});
            if($(this).attr('sort')==sortStr){
                $(this).attr('sort','-'+sortStr);
                $(this).html($(this).html()+'<span class="glyphicon glyphicon-triangle-top"></span>');
            }else if('-'+$(this).attr('sort')==sortStr){
                $(this).html($(this).html()+'<span class="glyphicon glyphicon-triangle-bottom"></span>');
            }
        }
    })
    //表头排序
    $('.myProject-table thead tr th ').click(function () {
        if($(this).attr('sort')!=undefined){
            //var newUrl=window.location.href;
            var newUrl=funcUrlDel('sort');
            if(newUrl.indexOf('?') > 0){
                window.location.href=newUrl+'&sort='+$(this).attr('sort');
            }else{
                window.location.href=newUrl+'?sort='+$(this).attr('sort');
            }
        }
    })
    // 删除url中某个参数,并跳转
    function funcUrlDel(name){
        var loca = window.location;
        var baseUrl = loca.origin + loca.pathname + "?";
        var query = loca.search.substr(1);
        if (query.indexOf(name)>-1) {
            var obj = {}
            var arr = query.split("&");
            for (var i = 0; i < arr.length; i++) {
                arr[i] = arr[i].split("=");
                obj[arr[i][0]] = arr[i][1];
            };
            delete obj[name];
            var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g,"").replace(/\:/g,"=").replace(/\,/g,"&");
            return url
        }
        return window.location.href;
    }
    //修改权限
    $("#setPermission").click(function (data) {
        var project_id = 1;
        var state = 0;
        $.each($(".selinput"), function(i, value) {
            if ($(this).is(":checked")){
                project_id = $(this).val();
                state += 1;
            }

        });

        if (state != 1){
            layer.msg('请先选中项目,或只选择1个项目');
            return false;
        }

        if(project_id){
            $.get('/project/set-permissions',{'projectid':project_id},function (data) {
                if(data=='0' || data.status=="false" || data.status==false){
                    $("#myModal").html("<div style='padding:100px;color:#fff;text-align:center;font-size:26px;'>没有权限访问</div>");
                }else{
                    $("#myModal").html(data);
                }
            })
        }
    });

    //配置团队
    $("#setTeam").click(function (data) {
        var project_id = 1;
        var state = 0;
        $.each($(".selinput"), function(i, value) {
            if ($(this).is(":checked")){
                project_id = $(this).val();
                state += 1;
            }

        });

        if (state != 1){
            layer.msg('请先选中项目,或只选择1个项目');
            return false;
        }

        if(project_id){
            $.get('/project/set-teams',{'projectid':project_id},function (data) {
                if(data=='0' || data.status=="false" || data.status==false){
                    $("#myModal2").html("<div style='padding:100px;color:#fff;text-align:center;font-size:26px;'>没有权限访问</div>");
                }else{
                    $("#myModal2").html(data);
                }
            })
        }
    });



</script>

